package com.acorn.community.service.user.impl;

import com.acorn.community.client.req.GetUserAccountByUserIdReq;
import com.acorn.community.client.resp.GetUserAccountByUserIdResp;
import com.acorn.community.dao.repository.user.UserAccountRepository;
import com.acorn.community.entity.user.UserAccountEntity;
import com.acorn.community.service.user.UserAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 用户账户
 *
 * @author tianshiwei
 */
@Slf4j
@Service
public class UserAccountServiceImpl implements UserAccountService {

    @Resource
    private UserAccountRepository userAccountRepository;

    @Override
    public GetUserAccountByUserIdResp getUserAccountByUserId(GetUserAccountByUserIdReq getUserAccountByUserId) {
        log.info("getUserAccountByUserId param:{}", getUserAccountByUserId);
        UserAccountEntity entity = userAccountRepository.getEntityById(getUserAccountByUserId.getUserId());
        log.info("getUserAccountByUserId param:{},entity:{}", getUserAccountByUserId, entity);
        if (Objects.isNull(entity)) {
            return new GetUserAccountByUserIdResp();
        }
        GetUserAccountByUserIdResp resp = GetUserAccountByUserIdResp.builder().balance(entity.getBalance()).build();
        log.info("getUserAccountByUserId param:{},entity:{},return:{}", getUserAccountByUserId, entity, resp);
        return resp;
    }
}
